package com.zh;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/servlet")
public class servletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String result = req.getParameter("result");

        BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/eddie/workspace/java/work/My_servlet1/src/com/zh/a.txt", true));
        bw.write(name + " " + age + " " + result);
        bw.newLine();
        bw.close();

        PrintWriter pw = resp.getWriter();
        pw.print("ok");
        pw.close();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
